package cn.anxingongyou.anxin.service.impl;

import cn.anxingongyou.anxin.entity.Taxi;
import cn.anxingongyou.anxin.entity.UserParent;
import cn.anxingongyou.anxin.entity.Work;
import cn.anxingongyou.anxin.entity.WorkerExpenditure;
import cn.anxingongyou.anxin.mapper.TaxiMapper;
import cn.anxingongyou.anxin.mapper.UserParentMapper;
import cn.anxingongyou.anxin.mapper.WorkMapper;
import cn.anxingongyou.anxin.mapper.WorkerExpenditureMapper;
import cn.anxingongyou.anxin.service.CountService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

@Service
public class CountServiceImpl implements CountService {

    private static final Logger logger = LoggerFactory.getLogger(CountServiceImpl.class);

    private final UserParentMapper userParentMapper;
    private final WorkMapper workMapper;
    private final TaxiMapper taxiMapper;
    private final WorkerExpenditureMapper workerExpenditureMapper;
    @Autowired
    public CountServiceImpl(UserParentMapper userParentMapper, WorkMapper workMapper, TaxiMapper taxiMapper, WorkerExpenditureMapper workerExpenditureMapper) {
        this.userParentMapper = userParentMapper;
        this.workMapper = workMapper;
        this.taxiMapper = taxiMapper;
        this.workerExpenditureMapper = workerExpenditureMapper;
    }

    @Override
    public Map<String, Object> countInfo() {
        Map<String,Object> result = new HashMap<>();
        UserParent userParent = new UserParent();
        //获取总用户的数量
        int countUser = userParentMapper.selectCount(userParent);
        result.put("countUser",countUser);
        logger.info("总用户的数量：{}",countUser);

        // 获取招聘者数量
        userParent.setIsEnterpriseCertification(1);
        int employerCount1 = userParentMapper.selectCount(userParent);
        result.put("enterpriseCertCount",employerCount1);
        logger.info("企业认证的数量：{}",employerCount1);

        userParent.setIsPersonalAuthentication(1);
        int employerCount3 = userParentMapper.selectCount(userParent);

        userParent.setIsEnterpriseCertification(0);
        int employerCount2 = userParentMapper.selectCount(userParent);
        result.put("employerCount",employerCount1 + employerCount2);
        logger.info("招聘者的数量：{}",employerCount1 + employerCount2);
        result.put("personalCertCount",employerCount3 + employerCount2);
        logger.info("个人认证的数量：{}",employerCount3 + employerCount2);


        // 总工作的数量
        int workCount = workMapper.selectCount(new Work());
        result.put("workCount",workCount);
        logger.info("工作的总数量：{}",workCount);

        // 查询车找人
        Taxi taxi = new Taxi();
        taxi.setMode(0);
        int carFindUser = taxiMapper.selectCount(taxi);
        result.put("carFindUser",carFindUser);
        logger.info("车找人的总数量",carFindUser);

        // 人找车
        taxi.setMode(1);
        int userFindCar = taxiMapper.selectCount(taxi);
        result.put("userFindCar",userFindCar);
        logger.info("人找车的总数量",userFindCar);

        // 待提现
        WorkerExpenditure workerExpenditure = new WorkerExpenditure();
        workerExpenditure.setCashStatus(0);
        int moneying = workerExpenditureMapper.selectCount(workerExpenditure);
        result.put("moneying",moneying);
        logger.info("待提现",moneying);

        // 已提现
        workerExpenditure.setCashStatus(1);
        int moneyed = workerExpenditureMapper.selectCount(workerExpenditure);
        result.put("moneyed",moneyed);
        logger.info("已提现",moneyed);

        return result;
    }
}
